package io.ouka.jvm.hotspot.selfread.methodinvoke;

import java.util.Arrays;
import java.util.Stack;

/**
 * @author ouka
 * StackValueCollection
 */
public class StackValueCollection {
    ///////////////操作数栈
    private Stack<StackValue> stackValueStack = new Stack();



    public StackValueCollection() {
    }
    public void push(StackValue value) {
        getStackValueStack().push(value);
    }

    public StackValue pop() {
        return getStackValueStack().pop();
    }

    public StackValue peek() {
        return getStackValueStack().peek();
    }

    ///////////////////////局部变量表
    private int maxLength;//属性个数
    private int index;//索引
    private StackValue[] locals;//表

    public StackValueCollection(int size) {
        maxLength = size;

        locals = new StackValue[size];
    }

    public void add(int index, StackValue value) {
        getLocals()[index] = value;
    }

    public StackValue get(int index) {
        return getLocals()[index];
    }

    public Stack<StackValue> getStackValueStack() {

        return stackValueStack;
    }

    public void setStackValueStack(Stack<StackValue> stackValueStack) {
        this.stackValueStack = stackValueStack;
    }

    public int getMaxLength() {
        return maxLength;
    }

    public void setMaxLength(int maxLength) {
        this.maxLength = maxLength;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public StackValue[] getLocals() {
        return locals;
    }

    public void setLocals(StackValue[] locals) {
        this.locals = locals;
    }

    @Override
    public String toString() {
        return "StackValueCollection{" +
                "stackValueStack=" + stackValueStack +
                ", maxLength=" + maxLength +
                ", index=" + index +
                ", locals=" + Arrays.toString(locals) +
                '}';
    }
}
